//******************************************************************************
//this code is protected by the GNU affero GPLv3
//author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
//                        <digital.ragnarok AT gmail dot com>
//******************************************************************************
#include "globals.h"

static s8 create_data_source(struct client *c,struct msg *m)
{
  s8 r;
  if(m->req_dws<3){
    PERR("client(%d):fatal:data_device_manager::create_data_source missing"
                                                       " data_source_id",c->so);
    r=LWL_ERR;goto exit;
  }

  LOG_WIRE("client(%d):data_device_manager::create_data_source"
                                        " data_source_id=%u\n",c->so,m->req[2]);

  r=data_device_manager_create_data_source(c,m->req[2]);
exit:
  return r;
}

static s8 get_data_device(struct client *c,struct msg *m)
{
  s8 r;
  if(m->req_dws<4){
    PERR("client(%d):fatal:data_device_manager::get_data_device missing data\n"
                                                                        ,c->so);
    r=LWL_ERR;goto exit;
  }

  LOG_WIRE("client(%d):data_device_manager::get_data_device data_device_id=%u" 
                                     " seat_id=%u\n",c->so,m->req[2],m->req[3]);

  r=data_device_manager_get_data_device(c,m->req[2],m->req[3]);
exit:
  return r;
}

s8 wl_data_device_manager_req(struct client *c,struct msg *m)
{
  s8 r;
  switch(m->req_op){
  case WL_DATA_DEVICE_MANAGER_CREATE_DATA_SOURCE:
    r=create_data_source(c,m);
    break;
  case WL_DATA_DEVICE_MANAGER_GET_DATA_DEVICE:
    r=get_data_device(c,m);
    break;
  default:
    PERR("client(%d):fatal:data_device_manager unknown opcode %u\n",c->so,
                                                                     m->req_op);
    r=LWL_ERR;
  };
  return r;
}
